package com.example.supermarket.service.impl;

import com.example.supermarket.entity.PageBean;
import com.example.supermarket.entity.User;
import com.example.supermarket.exception.PasswordNotException;
import com.example.supermarket.exception.UserNameNotExistException;
import com.example.supermarket.mapper.UserMapper;
import com.example.supermarket.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2023-10-13
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public User login(String userName, String userPwd) {
        User user=userMapper.getUserByUserName(userName);
        if (user==null){
            throw new UserNameNotExistException("用户不存在");
        }

        if(!DigestUtils.md5DigestAsHex(userPwd.getBytes()).equals(user.getUserPwd())){
            throw new PasswordNotException("密码错误");
        }
        return user;
    }

    @Override
    public User getUserById(int userId) {

        return userMapper.getUserById(userId);
    }

    @Override
    public PageBean<User> getUsers(int pageNum, int pageSize, User user) {
        return null;
    }

    @Override
    public void addUser(User user) {

    }

    @Override
    public boolean emailExists(String useremail) {
        return false;
    }

    @Override
    public boolean nameExists(String username) {
        return false;
    }
}
